package com.pureut.system.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.system.domain.vo.MaterialCertificationApplicationVo;
import com.pureut.system.service.IMaterialCertificationApplicationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;


/**
 * @Author: pureut
 * @Date: 2024-12-04 18:23:47
 * @Desc: tq认证申请Controller
 */
@RestController
@RequestMapping("/material/iq")
public class IqCertificationApplicationController extends BaseController {

    /**
     * 物料认证申请Service
     */
    @Resource
    private IMaterialCertificationApplicationService materialCertificationApplicationService;

    /**
     * 查询物料认证申请列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialCertificationApplication-list")
    @GetMapping("/list")
    public TableDataInfo list( MaterialCertificationApplicationVo materialCertificationApplicationVo) {
        materialCertificationApplicationVo.setDataType("2");
        startPage();
        return getDataTable(materialCertificationApplicationService.queryPage(materialCertificationApplicationVo));

    }

    /**
     * 获取物料认证申请详细信息
     * @param: id 物料认证申请主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialCertificationApplication-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(materialCertificationApplicationService.getInfoById(id));
    }

    /**
     * 新增物料认证申请
     * @param: materialCertificationApplication 物料认证申请对象
     * @return: Json工具类对象
     */
    @Log(title = "新增IQ认证申请", businessType = BusinessType.INSERT)
    //    @SaCheckPermission("materialCertificationApplication-add")
    @PostMapping
    public AjaxResult add(@RequestBody MaterialCertificationApplicationVo materialCertificationApplicationVo) {
        materialCertificationApplicationVo.setDataType("2");
        return toAjax(materialCertificationApplicationService.save(materialCertificationApplicationVo));
    }

    /**
     * 修改物料认证申请
     * @param: materialCertificationApplication 物料认证申请对象
     * @return: Json工具类对象
     */
    @Log(title = "修改IQ认证申请", businessType = BusinessType.UPDATE)
    //    @SaCheckPermission("materialCertificationApplication-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody MaterialCertificationApplicationVo materialCertificationApplicationVo) {
        materialCertificationApplicationVo.setDataType("2");
        return toAjax(materialCertificationApplicationService.updateById(materialCertificationApplicationVo));
    }

    /**
     * 删除物料认证申请
     * @param: id 物料认证申请主键
     * @return: Json工具类对象
     */
    @Log(title = "删除TQ认证申请", businessType = BusinessType.DELETE)
    //    @SaCheckPermission("materialCertificationApplication-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(materialCertificationApplicationService.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 获取物料认证申请 初始化信息
     * @param: id 样品申请主键
     * @return: Json工具类对象
     */
    @GetMapping(value = "/infoInit")
    public AjaxResult infoInit() {
        return AjaxResult.success(materialCertificationApplicationService.infoInit());
    }

    /**
     * 审核
     * @param: id 样品申请主键
     * @return: Json工具类对象
     */
    @PostMapping(value = "/examine")
    public AjaxResult examine(@RequestBody MaterialCertificationApplicationVo materialCertificationApplicationVo) {
        return toAjax(materialCertificationApplicationService.examine(materialCertificationApplicationVo));
    }
}
